package com.umbrella;

import java.util.List;

public class ResultPage extends Result {

	private Page page;
	
	public ResultPage(Object result, Page page, Integer resultCode, String resultMsg){
		super(result, resultCode, resultMsg);
		this.page = page;
	}

	public ResultPage(Object result, Page page){
		super(result);
		this.page = page;
	}
	
	public Page getPage() {
		return page;
	}
	
	public static ResultPage parsePage(List<? extends Object> list, Integer pageSize, Integer pageNo){
		Integer hasNext = 0;
		if(list.size()>pageSize){
			
			list.remove(list.size()-1);
			hasNext = 1;
		}
		Page page = new Page(pageSize, pageNo, hasNext);
		return new ResultPage(list, page);
	}

	public static ResultPage parsePage(List<? extends Object> list, Page page){

		return ResultPage.parsePage(list, page.getPageSize(), page.getPageNo());
	}
}
